﻿using System;
using System.IO;

namespace PokemonBattle.PokemonData
{
    /// <summary>
    /// Details:
    /// 0 Contact
    /// 1 Sound
    /// 2 KingRock
    /// 3 Snatchable
    /// 4 AttackAtTarget
    /// 5 Substitute
    /// 6 Protectable
    /// 7 Punch
    /// </summary>
    [Serializable()]
    public class MoveData : DataStream
    {
        public MoveData()
        {
            this.Details = new bool[8];
            //0.接触, 1.声音, 7.拳击, 2.王证, 3.抢夺
        }

        #region props

        public double Accuracy { get; set; }
        public MoveAdditionalEffect AddEffect1 { get; set; }
        public MoveAdditionalEffect AddEffect2 { get; set; }
        public double AddEffectOdds { get; set; }
        public bool[] Details { get; set; }
        public MoveEffect Effect { get; set; }
        public string Info { get; set; }
        public MoveType MoveType { get; set; }
        public string Name { get; set; }
        public int Power { get; set; }
        public int PP { get; set; }
        public int Priority { get; set; }
        public MoveTarget Target { get; set; }
        public string Type { get; set; }

        #endregion

        #region abstract

        public override void Load(Stream input)
        {
            BinaryReader reader = new BinaryReader(input);
            this.MoveType = (MoveType)reader.ReadInt32();
            this.Target = (MoveTarget)reader.ReadInt32();
            this.Effect = (MoveEffect)reader.ReadInt32();
            this.AddEffect1 = (MoveAdditionalEffect)reader.ReadInt32();
            this.AddEffect2 = (MoveAdditionalEffect)reader.ReadInt32();
            this.Name = reader.ReadString();
            this.Type = reader.ReadString();
            this.Info = reader.ReadString();
            this.PP = reader.ReadInt32();
            this.Power = reader.ReadInt32();
            this.Priority = reader.ReadInt32();
            this.Accuracy = reader.ReadDouble();
            this.AddEffectOdds = reader.ReadDouble();
            for (int i = 0; i < 8; i++)
            {
                this.Details[i] = reader.ReadBoolean();
            }
        }

        public override void Save(Stream output)
        {
            BinaryWriter writer = new BinaryWriter(output);
            writer.Write((int)this.MoveType);
            writer.Write((int)this.Target);
            writer.Write((int)this.Effect);
            writer.Write((int)this.AddEffect1);
            writer.Write((int)this.AddEffect2);
            writer.Write(this.Name);
            writer.Write(this.Type);
            writer.Write(this.Info);
            writer.Write(this.PP);
            writer.Write(this.Power);
            writer.Write(this.Priority);
            writer.Write(this.Accuracy);
            writer.Write(this.AddEffectOdds);
            for (int i = 0; i < 8; i++)
            {
                writer.Write(this.Details[i]);
            }
        }

        #endregion

        public static MoveData FromStream(Stream input)
        {
            return FromStream<MoveData>(input);
        }
    }
}